package com.ksm.zyz.controller;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksm.zyz.common.base.BaseController;
import com.ksm.zyz.sys.entity.BsData;
import com.ksm.zyz.sys.entity.ExtData;
import com.ksm.zyz.sys.entity.OrderInstockGoods;
import com.ksm.zyz.sys.entity.OrderInstockInfo;
import com.ksm.zyz.sys.serverentity.sOrderInstockGoods;
import com.ksm.zyz.sys.serverentity.sOrderInstockInfo;
import com.ksm.zyz.sys.serverservice.sOrderInstockGoodsService;
import com.ksm.zyz.sys.serverservice.sOrderInstockInfoService;
import com.ksm.zyz.sys.service.orderInstockGoodsService;
import com.ksm.zyz.sys.service.orderInstockInfoService;

/**
 * @author liuhao
 *
 */
@Controller
@RequestMapping("OrderInstockTongBu")
public class OrderInstockController extends BaseController<OrderInstockInfo> {

	@Autowired
	private sOrderInstockInfoService sService;
	@Autowired
	private orderInstockInfoService Service;
	@Autowired
	private sOrderInstockGoodsService sGoodsService;
	@Autowired
	private orderInstockGoodsService GoodsService;
	
	

	   @RequestMapping(value ="OrderInstockInfo")
	    @ResponseBody
		public ExtData OrderInstockInfo(int ming, HttpServletRequest req){
	         //List<sOrderGoodsInfo> list=sgoodsService.selectSome();
		   int scount=(int)sService.selectAllCount();
		   int count=(int)Service.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   int size=2000;
		   for(int i=begin;i<=scount+size;i=i+size)
		   {
			   sOrderInstockInfo sinfo =new sOrderInstockInfo();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(i);
			   bsdata.setLimit(size);
			   sinfo.setBsData(bsdata);
			   List<OrderInstockInfo> list=sService.selectAllInfo(sinfo);
			   for(int j=0;j<list.size();j++)
			   {
				   OrderInstockInfo info=list.get(j);
				   System.out.println(list.get(j).getOrderOperator());
				   info.setSmId(ming);
				   info.setOrderNum(info.getOrderNum()+ming);				   				   
				  try
				   {
					   Service.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getId()+"@@@@@"+info.getOrderNum());
					   extData.setTotalCount(i+j);
					   return extData;   
				   }
				   
			   }
			   extData.setTotalCount(scount-count);	  			   
		   }
		   
	               
			return extData;    
		}
	   @RequestMapping(value ="OrderInstockGoods")
	    @ResponseBody
		public ExtData OrderInstockGoods(int ming, HttpServletRequest req){
	         //List<sOrderGoodsInfo> list=sgoodsService.selectSome();
		   int scount=(int)sGoodsService.selectAllCount();
		   int count=(int)Service.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   int size=2000;
		   for(int i=begin;i<=scount+size;i=i+size)
		   {
			   sOrderInstockGoods sGoodsinfo =new sOrderInstockGoods();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(i);
			   bsdata.setLimit(size);
			   sGoodsinfo.setBsData(bsdata);
			   List<OrderInstockGoods> list=sGoodsService.selectAllInfo(sGoodsinfo);
			   for(int j=0;j<list.size();j++)
			   {
				   OrderInstockGoods Goodsinfo=list.get(j);
				   System.out.println(list.get(j).getGoodsName());
				   Goodsinfo.setSmId(ming);
				   Goodsinfo.setOrderNum(Goodsinfo.getOrderNum()+ming);	
				  try
				   {
					   GoodsService.insertSelective(Goodsinfo);					   
				   }
				   catch(Exception e){
					   System.out.println(Goodsinfo.getId()+"@@@@@"+Goodsinfo.getOrderNum());
					   extData.setTotalCount(i+j);
					   return extData;   
				   }
				   
			   }
			   extData.setTotalCount(scount-count);	  			   
		   }
		   
	               
			return extData;    
		}
	

}
